home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / CIncludesTool / modified version / source files / locate.c < prev    next >
Text File  |  1991-08-28  |  1KB  |  67 lines

  1. // locate.c
  2. //
  3. // searching functions for CIncludesCode MPW tool
  4.  
  5. #include <Memory.h>
  6. #include <StdIO.h>
  7. #include <String.h>
  8. #include "CIncludesCode.h"
  9.  
  10. extern Handle database;
  11. extern dataHeaderType dataHeader;
  12.  
  13. char *getDictionaryPtr(char ch)
  14. {
  15. long offset;
  16.  
  17. offset = dataHeader.dictionaryOffsets[dictionaryIndex(ch)];
  18. return (StripAddress(*database) + offset);
  19. }  // getDictionaryPtr()
  20.  
  21. char *getNamePtr(short index)
  22. {
  23. strArray *sp = (strArray*) (*database + dataHeader.nameArrayOffset);
  24.  
  25. return ((char*) ((*sp)[index]));
  26. }  // getNamePtr()
  27.  
  28. char *search(char *s,char* dictPtr)
  29. // returns pointer or NIL
  30.  
  31. {
  32. char *p = dictPtr + (4 + 2 + 4);            // endOffset = 4,fileIndex = 2,filePosition = 4
  33. char *limit    = dictPtr + *((long*) dictPtr);
  34.  
  35. if (*s)
  36.     {
  37.     while (p < limit)
  38.         {
  39.         if (strcmp(p,s) == 0)
  40.             {
  41.             return (p - (2 + 4));            // fileIndex = 2,filePosition = 4
  42.             }  // if strcmp()
  43.         else
  44.             {
  45.             p += strlen(p) + (2 + 4 + 1);    // fileIndex = 2,filePosition = 4,'\0' = 1
  46.             }  // else if strcmp()
  47.         }  // while p
  48.     }  // if *s
  49. return 0;
  50. }  // search()
  51.  
  52. Boolean    locateIdentifier(char *dest,long *filePosition,char *src)
  53. {
  54. char *entryPtr = search(src,getDictionaryPtr(*src));
  55. char *p;
  56.  
  57. if (entryPtr)
  58.     {
  59.     p = getNamePtr(getShort(entryPtr));
  60.     strcpy(dest,p);
  61.     *filePosition = getLong(entryPtr + 2);
  62.     }  // if entryPtr
  63.  
  64. return ((Boolean) entryPtr);
  65. }  // locateIdentifier()
  66.  
  67. // end of locate.c